home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 234_01 / ydir.c < prev    next >
Text File  |  1987-06-16  |  6KB  |  293 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     XDIR - Hard Disk Manager
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Apr 03, 1987
  6.   DESCRIPTION:     Hard Disk Manager for IBM PC
  7.   KEYWORDS:     Hard Disk Manager Dump Directory
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      ydir.C
  10.   WARNINGS:     None
  11.   CRC:         N/A
  12.   SEE-ALSO:     HDIR.DOC and XDIR.DOC
  13.   AUTHOR:     Mike Blakley 15645 SW 82 Cir Ln #76, Miami, Fl 33193
  14.   COMPILERS:     ECO-C
  15.   REFERENCES:     XDIR.DOC
  16. */
  17.  
  18.  
  19. /*
  20.    ydir.c
  21.    functions associated with routine xdir
  22.    to process the DOS directories
  23. */
  24. #include "stdio.h"
  25. #include "dos.h"
  26. #include "dir.h"
  27. #include "xdir.h"
  28.  
  29. /*
  30.     format print for a directory entry
  31.  
  32. */
  33. void dirform(cp,buffer)
  34. struct tdir *cp;     /* directory structure */
  35. char *buffer;        /* output buffer */
  36. {
  37.  
  38.       char temp1[100];
  39.       char temp[12];
  40.       char *op;      /* pointer to output */
  41.       int  yr, mo, da, hr, mn;
  42.       int  i;
  43.  
  44.       op = buffer;   /* init pointer to output */
  45.       clear(temp1,100,' ');
  46.       blockmv(temp1,cp->d_name,strlen(cp->d_name));  /* file name */
  47.       op = temp1 + 20;
  48.       i = (int) cp->d_attrib;
  49.       if (i & 0x20) temp1[20] = 'a';
  50.       if (i & 0x10) temp1[21] = 'd';
  51.       if (i & 0x08) temp1[22] = 'l';
  52.       if (i & 0x04) temp1[23] = 's';
  53.       if (i & 0x02) temp1[24] = 'h';
  54.       if (i & 0x01) temp1[25] = 'r';
  55.  
  56.       mo = (((cp->d_date)>>5) & 0xf);
  57.       da = (cp->d_date & 0x1f);
  58.       yr = (((cp->d_date)>>9) & 0x3f);
  59.       yr += 80;
  60.       hr = (((cp->d_time) >>11) & 0x1f);
  61.       mn = (((cp->d_time) >> 5) & 0x3f);
  62.  
  63.       ltoa(temp,cp->d_size);
  64.       i = strlen(temp);
  65.       blockmv(temp1+34-i,temp,strlen(temp));
  66.  
  67.       prin(mo,temp);
  68.       blockmv(temp1+35,temp,2);
  69.  
  70.       temp1[37] = '/';
  71.       prin(da,temp);
  72.       blockmv(temp1+38,temp,2);
  73.       temp1[40] = '/';
  74.       prin(yr,temp);
  75.       blockmv(temp1+41,temp,2);
  76.  
  77.       if (hr > 12) {hr -= 12; temp1[49] = 'p';}
  78.       else temp1[49] = 'a';
  79.  
  80.       prin(hr,temp);
  81.       blockmv(temp1+44,temp,2);
  82.       temp1[46] = ':';
  83.       prin(mn,temp);
  84.       blockmv(temp1+47,temp,2);
  85.       blockmv(temp1+51,cp->d_path,strlen(cp->d_path)+1);
  86.       strcpy(buffer,temp1);
  87.       return;
  88.  
  89. }
  90.  
  91. /*
  92.    cvdate
  93.    convert date to unsigned format
  94.  
  95. */
  96. int cvdate(buffer)
  97. char *buffer;
  98. {
  99.      int yr, mo, da;
  100.      char temp[3];
  101.  
  102.      int cdate = 0;
  103.      if (strlen(buffer) != 6) return 0;
  104.      temp[0] = buffer[0];
  105.      temp[1] = buffer[1];
  106.      temp[2] = 0;
  107.      yr = atoi(temp);
  108.      yr -= 80;
  109.      temp[0] = buffer[2];
  110.      temp[1] = buffer[3];
  111.      mo = atoi(temp);
  112.      temp[0] = buffer[4];
  113.      temp[1] = buffer[5];
  114.      da = atoi(temp);
  115.      cdate = da;
  116.      cdate |= (mo << 5);
  117.      cdate |= (yr << 9);
  118.      return (cdate);
  119. }
  120.  
  121.  
  122. /*
  123.     lis
  124.     this function will list  a file to the printer
  125.     updated 7/11/86 to detect printer errors
  126. */
  127. void lis(filename)
  128. char *filename;
  129. {
  130.     int  act,i,eval;
  131.     char buffer[100];
  132.     int  linecnt;       /* count of lines */
  133.     int  stdlist;
  134.  
  135.     stdlist = open("PRN",1);     /* open for writing */
  136.  
  137.     act = 1;
  138.     linecnt = 0;
  139.     while (1)
  140.     {
  141.     i = getxline(buffer,100,filename,act);
  142.     if (i == -1) break;
  143.     act = 0;
  144.     if (linecnt == 0)          /* print title at top of page */
  145.        {
  146.        eval = tprt();
  147.        if (eval) {
  148.        write(stdlist,"List of file: ",14);
  149.        write(stdlist,filename,strlen(filename));
  150.           }
  151.           else {close(stdlist);return;}
  152.        }
  153.  
  154.     eval = tprt();            /* write detail line */
  155.     if (eval)
  156.     {
  157.     write(stdlist,"\n",1);
  158.     write(stdlist,buffer,strlen(buffer));
  159.     ++linecnt;
  160.     }
  161.     else {close(stdlist);return;}
  162.  
  163.     if (linecnt == 60)   /* form feed at end of logical page */
  164.        {
  165.        eval = tprt();
  166.        if (eval)
  167.        {
  168.        write(stdlist,"\f",1);
  169.        linecnt = 0;
  170.        }
  171.        else {close(stdlist);return;}
  172.        }
  173.     }
  174.  
  175.     eval = tprt();
  176.     if (eval)
  177.     write(stdlist,"\f",1);    /* last page */
  178.     close(stdlist);
  179.  
  180. }                             /* end of function */
  181.  
  182.  
  183.  
  184. /*
  185.    get1char
  186.    get a single character
  187.  
  188. */
  189. get1char(cntl)
  190. int *cntl;
  191. {
  192.     int c;
  193.  
  194.     c = getch();
  195.     if (c==0)
  196.        {
  197.        *cntl = 1;
  198.        c = getch();
  199.        }
  200.     else *cntl = 0;
  201.  
  202.     return c;
  203.  
  204. }
  205.  
  206. /*
  207.    cvatt
  208.    convert attributes
  209. */
  210. int cvatt(buffer)
  211. char *buffer;
  212. {
  213.      int  c, rc;
  214.  
  215.      rc = 0;    /* init the return code */
  216.      while (c = toupper((int) *buffer++))
  217.      {
  218.      switch (c)
  219.      {
  220.      case 'A':    /* all */
  221.        rc |= 0x3f;
  222.        break;
  223.      case 'R':    /* readonly */
  224.        rc |= 0x01;
  225.        break;
  226.      case 'H':    /* hidden */
  227.        rc |= 0x02;
  228.        break;
  229.      case 'S':    /* system */
  230.        rc |= 0x04;
  231.        break;
  232.      case 'V':    /* volume */
  233.        rc |= 0x08;
  234.        break;
  235.      case 'D':    /* directory */
  236.        rc |= 0x10;
  237.        break;
  238.      case 'B':    /* archive bit */
  239.        rc |= 0x20;
  240.        break;
  241.      }            /* end switch */
  242.      }            /* end while */
  243.  
  244.      return rc;
  245.  
  246. }    /* end function */
  247.  
  248.  
  249. /*
  250.     prin
  251.     print a date or time in printable format
  252.  
  253. */
  254. void prin(mo,temp)
  255. int  mo;
  256. char *temp;
  257. {
  258.  
  259.      if (mo < 10)
  260.         {
  261.         temp[0] = '0';
  262.         temp[1] = mo + '0';
  263.         }
  264.      else itoa(temp,mo);
  265.  
  266.      temp[2] = 0;
  267.  
  268. }
  269. /*
  270.      test printer status
  271.      if unavailable display message and get action to take
  272.  
  273. */
  274. tprt()
  275. {
  276.     int  i;
  277.  
  278.     i = testprt();
  279.     if (i) return (1);     /* no error in printer */
  280.  
  281.     while (1)
  282.     {
  283.     writestr("\nPrinter error - action to take (A)bort (R)etry ");
  284.     i = toupper(getch());
  285.     if (i == 'A') return (0);
  286.     i = testprt();
  287.     if (i) return (1);
  288.     }
  289.  
  290. }
  291.  
  292.  
  293.